YAML : YAML parser and encoder

更新时间:
2024-05-13
下载文档

YAML : YAML parser and encoder

This module provides a lightweight YAML 1.2 Parser & Encoder.

User can use the following code to import the YAML module.

var YAML = require('yaml');

Support

The following shows YAML module APIs available for each permissions.

 User ModePrivilege Mode
YAML.parse
YAML.stringify

YAML Module

YAML.parse(input[, exceptionOnInvalidType[, objectDecoder]])

  • input {String} Yaml string.
  • exceptionOnInvalidType {Boolean} true if an exception must be thrown on invalid types, false otherwise. default: false.
  • objectDecoder {Function} A function to deserialize custom objects, default: null.
    • key {Any} The key associated with the value.
    • value {Any} The value produced by parsing.
    • Returns: {Any} Custom value.
  • Returns: {Object} YAML converted to a JavaScript object.

Example

YAML.parse("- apple\n- banana\n- carrot");
// ['apple', 'banana', 'carrot']

YAML.stringify(input[, inline[, indent[, exceptionOnInvalidType[, objectEncoder]]]])

  • input {Object} JavaScript object.
  • inline {Integer} The level where you switch to inline YAML. default: 2.
  • indent {Integer} The amount of spaces to use for indentation of nested nodes. default: 4.
  • exceptionOnInvalidType {Boolean} true if an exception must be thrown on invalid types (a JavaScript resource or object), false otherwise. default: false.
  • objectEncoder {Function} A function to serialize custom objects. default: null.
    • key {Any} The key associated with the value.
    • value {Any} The value produced by parsing.
    • Returns: {Any} Custom value.
  • Returns: {String} A YAML string representing the original JavaScript object.

Example

YAML.stringify({ a: 10, b: 20, c: [1, 2, 3] });
/*
a: 10
b: 20
c:
    - 1
    - 2
    - 3
*/
文档内容是否对您有所帮助?
有帮助
没帮助